home *** CD-ROM | disk | FTP | other *** search
- package sun.print;
-
- import java.awt.Color;
- import java.awt.Frame;
- import java.awt.Graphics2D;
- import java.awt.GraphicsConfiguration;
- import java.awt.GraphicsEnvironment;
- import java.awt.HeadlessException;
- import java.awt.Rectangle;
- import java.awt.Shape;
- import java.awt.geom.AffineTransform;
- import java.awt.geom.Point2D;
- import java.awt.geom.Rectangle2D;
- import java.awt.image.BufferedImage;
- import java.awt.print.Book;
- import java.awt.print.PageFormat;
- import java.awt.print.Pageable;
- import java.awt.print.Paper;
- import java.awt.print.Printable;
- import java.awt.print.PrinterAbortException;
- import java.awt.print.PrinterException;
- import java.awt.print.PrinterJob;
- import java.io.File;
- import java.io.FilePermission;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.security.AccessController;
- import java.util.ArrayList;
- import java.util.Locale;
- import javax.print.DocFlavor;
- import javax.print.DocPrintJob;
- import javax.print.PrintException;
- import javax.print.PrintService;
- import javax.print.PrintServiceLookup;
- import javax.print.ServiceUI;
- import javax.print.StreamPrintService;
- import javax.print.StreamPrintServiceFactory;
- import javax.print.DocFlavor.SERVICE_FORMATTED;
- import javax.print.attribute.Attribute;
- import javax.print.attribute.AttributeSet;
- import javax.print.attribute.HashPrintRequestAttributeSet;
- import javax.print.attribute.PrintRequestAttributeSet;
- import javax.print.attribute.standard.Copies;
- import javax.print.attribute.standard.Destination;
- import javax.print.attribute.standard.Fidelity;
- import javax.print.attribute.standard.JobName;
- import javax.print.attribute.standard.JobSheets;
- import javax.print.attribute.standard.Media;
- import javax.print.attribute.standard.MediaPrintableArea;
- import javax.print.attribute.standard.MediaSize;
- import javax.print.attribute.standard.MediaSizeName;
- import javax.print.attribute.standard.OrientationRequested;
- import javax.print.attribute.standard.PageRanges;
- import javax.print.attribute.standard.PrinterIsAcceptingJobs;
- import javax.print.attribute.standard.PrinterState;
- import javax.print.attribute.standard.PrinterStateReason;
- import javax.print.attribute.standard.PrinterStateReasons;
- import javax.print.attribute.standard.RequestingUserName;
- import javax.print.attribute.standard.SheetCollate;
- import javax.print.attribute.standard.Sides;
- import javax.print.attribute.standard.MediaSize.NA;
- import sun.awt.image.ByteInterleavedRaster;
- import sun.security.action.GetPropertyAction;
-
- public abstract class RasterPrinterJob extends PrinterJob {
- protected static final int PRINTER = 0;
- protected static final int FILE = 1;
- protected static final int STREAM = 2;
- private static final int MAX_BAND_SIZE = 4194304;
- private static final float DPI = 72.0F;
- private static final String FORCE_PIPE_PROP = "sun.java2d.print.pipeline";
- private static final String FORCE_RASTER = "raster";
- private static final String FORCE_PDL = "pdl";
- private static final String SHAPE_TEXT_PROP = "sun.java2d.print.shapetext";
- public static boolean forcePDL = false;
- public static boolean forceRaster = false;
- public static boolean shapeTextProp = false;
- private int cachedBandWidth = 0;
- private int cachedBandHeight = 0;
- private BufferedImage cachedBand = null;
- private int mNumCopies = 1;
- private boolean mCollate = false;
- private int mFirstPage = -1;
- private int mLastPage = -1;
- private Pageable mDocument = new Book();
- private String mDocName = new String("Java Printing");
- private boolean performingPrinting = false;
- private boolean userCancelled = false;
- private FilePermission printToFilePermission;
- private ArrayList redrawList = new ArrayList();
- private int copiesAttr;
- private String jobNameAttr;
- private String userNameAttr;
- private PageRanges pageRangesAttr;
- protected Sides sidesAttr;
- protected String destinationAttr;
- protected boolean noJobSheet = false;
- protected int mDestType = 1;
- protected String mDestination = "";
- protected boolean collateAttReq = false;
- protected boolean landscapeRotates270 = false;
- protected PrintRequestAttributeSet attributes = null;
- protected PrintService myService;
- public static boolean debugPrint;
- private int deviceWidth;
- private int deviceHeight;
- private AffineTransform defaultDeviceTransform;
- private PrinterGraphicsConfig pgConfig;
-
- protected abstract double getXRes();
-
- protected abstract double getYRes();
-
- protected abstract double getPhysicalPrintableX(Paper var1);
-
- protected abstract double getPhysicalPrintableY(Paper var1);
-
- protected abstract double getPhysicalPrintableWidth(Paper var1);
-
- protected abstract double getPhysicalPrintableHeight(Paper var1);
-
- protected abstract double getPhysicalPageWidth(Paper var1);
-
- protected abstract double getPhysicalPageHeight(Paper var1);
-
- protected abstract void startPage(PageFormat var1, Printable var2, int var3) throws PrinterException;
-
- protected abstract void endPage(PageFormat var1, Printable var2, int var3) throws PrinterException;
-
- protected abstract void printBand(byte[] var1, int var2, int var3, int var4, int var5) throws PrinterException;
-
- public void saveState(AffineTransform var1, Shape var2, Rectangle2D var3, double var4, double var6) {
- GraphicsState var8 = new GraphicsState(this, (1)null);
- var8.theTransform = var1;
- var8.theClip = var2;
- var8.region = var3;
- var8.sx = var4;
- var8.sy = var6;
- this.redrawList.add(var8);
- }
-
- protected static PrintService lookupDefaultPrintService() {
- PrintService var0 = PrintServiceLookup.lookupDefaultPrintService();
- if (var0 != null && var0.isDocFlavorSupported(SERVICE_FORMATTED.PAGEABLE) && var0.isDocFlavorSupported(SERVICE_FORMATTED.PRINTABLE)) {
- return var0;
- } else {
- PrintService[] var1 = PrintServiceLookup.lookupPrintServices(SERVICE_FORMATTED.PAGEABLE, (AttributeSet)null);
- return var1.length > 0 ? var1[0] : null;
- }
- }
-
- public PrintService getPrintService() {
- if (this.myService == null) {
- PrintService var1 = PrintServiceLookup.lookupDefaultPrintService();
- if (var1 != null && var1.isDocFlavorSupported(SERVICE_FORMATTED.PAGEABLE)) {
- try {
- this.setPrintService(var1);
- this.myService = var1;
- } catch (PrinterException var5) {
- }
- }
-
- if (this.myService == null) {
- PrintService[] var2 = PrintServiceLookup.lookupPrintServices(SERVICE_FORMATTED.PAGEABLE, (AttributeSet)null);
- if (var2.length > 0) {
- try {
- this.setPrintService(var2[0]);
- this.myService = var2[0];
- } catch (PrinterException var4) {
- }
- }
- }
- }
-
- return this.myService;
- }
-
- public void setPrintService(PrintService var1) throws PrinterException {
- if (var1 == null) {
- throw new PrinterException("Service cannot be null");
- } else if (!(var1 instanceof StreamPrintService) && var1.getName() == null) {
- throw new PrinterException("Null PrintService name.");
- } else {
- PrinterState var2 = (PrinterState)var1.getAttribute(PrinterState.class);
- if (var2 == PrinterState.STOPPED) {
- PrinterStateReasons var3 = (PrinterStateReasons)var1.getAttribute(PrinterStateReasons.class);
- if (var3 != null && var3.containsKey(PrinterStateReason.SHUTDOWN)) {
- throw new PrinterException("PrintService is no longer available.");
- }
- }
-
- if (var1.isDocFlavorSupported(SERVICE_FORMATTED.PAGEABLE) && var1.isDocFlavorSupported(SERVICE_FORMATTED.PRINTABLE)) {
- this.myService = var1;
- } else {
- throw new PrinterException("Not a 2D print service: " + var1);
- }
- }
- }
-
- protected void updatePageAttributes(PrintService var1, PageFormat var2) {
- if (var1 != null && var2 != null) {
- float var3 = (float)Math.rint(var2.getPaper().getWidth() * (double)25400.0F / (double)72.0F) / 25400.0F;
- float var4 = (float)Math.rint(var2.getPaper().getHeight() * (double)25400.0F / (double)72.0F) / 25400.0F;
- Media[] var5 = (Media[])var1.getSupportedAttributeValues(Media.class, (DocFlavor)null, (AttributeSet)null);
- Object var6 = null;
-
- try {
- var6 = CustomMediaSizeName.findMedia(var5, var3, var4, 25400);
- } catch (IllegalArgumentException var14) {
- }
-
- if (var6 == null || !var1.isAttributeValueSupported((Attribute)var6, (DocFlavor)null, (AttributeSet)null)) {
- var6 = (Media)var1.getDefaultAttributeValue(Media.class);
- }
-
- OrientationRequested var7;
- switch (var2.getOrientation()) {
- case 0:
- var7 = OrientationRequested.LANDSCAPE;
- break;
- case 2:
- var7 = OrientationRequested.REVERSE_LANDSCAPE;
- break;
- default:
- var7 = OrientationRequested.PORTRAIT;
- }
-
- if (this.attributes == null) {
- this.attributes = new HashPrintRequestAttributeSet();
- }
-
- if (var6 != null) {
- this.attributes.add((Attribute)var6);
- }
-
- this.attributes.add(var7);
- float var8 = (float)(var2.getPaper().getImageableX() / (double)72.0F);
- float var9 = (float)(var2.getPaper().getImageableWidth() / (double)72.0F);
- float var10 = (float)(var2.getPaper().getImageableY() / (double)72.0F);
- float var11 = (float)(var2.getPaper().getImageableHeight() / (double)72.0F);
-
- try {
- this.attributes.add(new MediaPrintableArea(var8, var10, var9, var11, 25400));
- } catch (IllegalArgumentException var13) {
- }
-
- }
- }
-
- public PageFormat pageDialog(PageFormat var1) throws HeadlessException {
- if (GraphicsEnvironment.isHeadless()) {
- throw new HeadlessException();
- } else {
- GraphicsConfiguration var2 = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
- PrintService var3 = (PrintService)AccessController.doPrivileged(new 1(this, var2));
- if (var3 == null) {
- return var1;
- } else {
- this.updatePageAttributes(var3, var1);
- PageFormat var4 = this.pageDialog(this.attributes);
- return var4 == null ? var1 : var4;
- }
- }
- }
-
- public PageFormat pageDialog(PrintRequestAttributeSet var1) throws HeadlessException {
- if (GraphicsEnvironment.isHeadless()) {
- throw new HeadlessException();
- } else {
- GraphicsConfiguration var2 = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
- Rectangle var3 = var2.getBounds();
- int var4 = var3.x + var3.width / 3;
- int var5 = var3.y + var3.height / 3;
- PrintService var6 = (PrintService)AccessController.doPrivileged(new 2(this, var2));
- if (var6 == null) {
- return null;
- } else {
- ServiceDialog var7 = new ServiceDialog(var2, var4, var5, var6, SERVICE_FORMATTED.PAGEABLE, var1, (Frame)null);
- var7.show();
- if (var7.getStatus() == 1) {
- PrintRequestAttributeSet var8 = var7.getAttributes();
- Class var9 = SunAlternateMedia.class;
- if (var1.containsKey(var9) && var8.containsKey(var9)) {
- var1.remove(var9);
- }
-
- var1.addAll(var8);
- PageFormat var10 = this.defaultPage();
- OrientationRequested var11 = (OrientationRequested)var1.get(OrientationRequested.class);
- byte var12 = 1;
- if (var11 != null) {
- if (var11 == OrientationRequested.REVERSE_LANDSCAPE) {
- var12 = 2;
- } else if (var11 == OrientationRequested.LANDSCAPE) {
- var12 = 0;
- }
- }
-
- var10.setOrientation(var12);
- Object var13 = (Media)var1.get(Media.class);
- if (var13 == null) {
- var13 = (Media)var6.getDefaultAttributeValue(Media.class);
- }
-
- if (!(var13 instanceof MediaSizeName)) {
- var13 = MediaSizeName.NA_LETTER;
- }
-
- MediaSize var14 = MediaSize.getMediaSizeForName((MediaSizeName)var13);
- if (var14 == null) {
- var14 = NA.LETTER;
- }
-
- short var15 = 352;
- Paper var16 = new Paper();
- float[] var17 = var14.getSize(var15);
- double var18 = Math.rint((double)var17[0]);
- double var20 = Math.rint((double)var17[1]);
- var16.setSize(var18, var20);
- MediaPrintableArea var22 = (MediaPrintableArea)var1.get(MediaPrintableArea.class);
- double var23;
- double var25;
- double var27;
- double var29;
- if (var22 != null) {
- var23 = Math.rint((double)(var22.getX(25400) * 72.0F));
- var27 = Math.rint((double)(var22.getY(25400) * 72.0F));
- var25 = Math.rint((double)(var22.getWidth(25400) * 72.0F));
- var29 = Math.rint((double)(var22.getHeight(25400) * 72.0F));
- } else {
- if (var18 >= (double)432.0F) {
- var23 = (double)72.0F;
- var25 = var18 - (double)144.0F;
- } else {
- var23 = var18 / (double)6.0F;
- var25 = var18 * (double)0.75F;
- }
-
- if (var20 >= (double)432.0F) {
- var27 = (double)72.0F;
- var29 = var20 - (double)144.0F;
- } else {
- var27 = var20 / (double)6.0F;
- var29 = var20 * (double)0.75F;
- }
- }
-
- var16.setImageableArea(var23, var27, var25, var29);
- var10.setPaper(var16);
- return var10;
- } else {
- return null;
- }
- }
- }
- }
-
- public boolean printDialog(PrintRequestAttributeSet var1) throws HeadlessException {
- if (GraphicsEnvironment.isHeadless()) {
- throw new HeadlessException();
- } else {
- DialogTypeSelection var2 = (DialogTypeSelection)var1.get(DialogTypeSelection.class);
- if (var2 == DialogTypeSelection.NATIVE) {
- this.attributes = var1;
-
- try {
- this.debug_println("calling setAttributes in printDialog");
- this.setAttributes(var1);
- } catch (PrinterException var12) {
- }
-
- boolean var15 = this.printDialog();
- this.attributes = var1;
- return var15;
- } else {
- GraphicsConfiguration var3 = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
- PrintService var4 = (PrintService)AccessController.doPrivileged(new 3(this, var3));
- if (var4 == null) {
- return false;
- } else {
- Object var6 = null;
- Object var5;
- if (var4 instanceof StreamPrintService) {
- StreamPrintServiceFactory[] var16 = lookupStreamPrintServices((String)null);
- var5 = new StreamPrintService[var16.length];
-
- for(int var7 = 0; var7 < var16.length; ++var7) {
- ((Object[])var5)[var7] = var16[var7].getPrintService((OutputStream)null);
- }
- } else {
- var5 = (PrintService[])AccessController.doPrivileged(new 4(this));
- if (var5 == null || ((Object[])var5).length == 0) {
- var5 = new PrintService[]{var4};
- }
- }
-
- Rectangle var17 = var3.getBounds();
- int var8 = var17.x + var17.width / 3;
- int var9 = var17.y + var17.height / 3;
-
- PrintService var10;
- try {
- var10 = ServiceUI.printDialog(var3, var8, var9, (PrintService[])var5, var4, SERVICE_FORMATTED.PAGEABLE, var1);
- } catch (IllegalArgumentException var14) {
- var10 = ServiceUI.printDialog(var3, var8, var9, (PrintService[])var5, (PrintService)((Object[])var5)[0], SERVICE_FORMATTED.PAGEABLE, var1);
- }
-
- if (var10 == null) {
- return false;
- } else {
- if (!var4.equals(var10)) {
- try {
- this.setPrintService(var10);
- } catch (PrinterException var13) {
- this.myService = var10;
- }
- }
-
- return true;
- }
- }
- }
- }
- }
-
- public boolean printDialog() throws HeadlessException {
- if (GraphicsEnvironment.isHeadless()) {
- throw new HeadlessException();
- } else {
- HashPrintRequestAttributeSet var1 = new HashPrintRequestAttributeSet();
- var1.add(new Copies(this.getCopies()));
- var1.add(new JobName(this.getJobName(), (Locale)null));
- boolean var2 = this.printDialog(var1);
- if (var2) {
- JobName var3 = (JobName)var1.get(JobName.class);
- if (var3 != null) {
- this.setJobName(var3.getValue());
- }
-
- Copies var4 = (Copies)var1.get(Copies.class);
- if (var4 != null) {
- this.setCopies(var4.getValue());
- }
-
- Destination var5 = (Destination)var1.get(Destination.class);
- if (var5 != null) {
- try {
- this.mDestType = 1;
- this.mDestination = (new File(var5.getURI())).getPath();
- } catch (Exception var9) {
- this.mDestination = "out.prn";
- PrintService var7 = this.getPrintService();
- if (var7 != null) {
- Destination var8 = (Destination)var7.getDefaultAttributeValue(Destination.class);
- if (var8 != null) {
- this.mDestination = (new File(var8.getURI())).getPath();
- }
- }
- }
- } else {
- this.mDestType = 0;
- PrintService var6 = this.getPrintService();
- if (var6 != null) {
- this.mDestination = var6.getName();
- }
- }
- }
-
- return var2;
- }
- }
-
- public void setPrintable(Printable var1) {
- this.setPageable(new OpenBook(this.defaultPage(new PageFormat()), var1));
- }
-
- public void setPrintable(Printable var1, PageFormat var2) {
- this.setPageable(new OpenBook(var2, var1));
- this.updatePageAttributes(this.getPrintService(), var2);
- }
-
- public void setPageable(Pageable var1) throws NullPointerException {
- if (var1 != null) {
- this.mDocument = var1;
- } else {
- throw new NullPointerException();
- }
- }
-
- protected void initPrinter() {
- }
-
- protected boolean isSupportedValue(Attribute var1, PrintRequestAttributeSet var2) {
- PrintService var3 = this.getPrintService();
- return var1 != null && var3 != null && var3.isAttributeValueSupported(var1, SERVICE_FORMATTED.PAGEABLE, var2);
- }
-
- protected void setAttributes(PrintRequestAttributeSet var1) throws PrinterException {
- this.setCollated(false);
- this.sidesAttr = null;
- this.pageRangesAttr = null;
- this.copiesAttr = 0;
- this.jobNameAttr = null;
- this.userNameAttr = null;
- this.destinationAttr = null;
- this.collateAttReq = false;
- PrintService var2 = this.getPrintService();
- if (var1 != null && var2 != null) {
- boolean var3 = false;
- Fidelity var4 = (Fidelity)var1.get(Fidelity.class);
- if (var4 != null && var4 == Fidelity.FIDELITY_TRUE) {
- var3 = true;
- }
-
- if (var3) {
- AttributeSet var5 = var2.getUnsupportedAttributes(SERVICE_FORMATTED.PAGEABLE, var1);
- if (var5 != null) {
- throw new PrinterException("Fidelity cannot be satisfied");
- }
- }
-
- SheetCollate var24 = (SheetCollate)var1.get(SheetCollate.class);
- if (this.isSupportedValue(var24, var1)) {
- this.setCollated(var24 == SheetCollate.COLLATED);
- }
-
- this.sidesAttr = (Sides)var1.get(Sides.class);
- if (!this.isSupportedValue(this.sidesAttr, var1)) {
- this.sidesAttr = Sides.ONE_SIDED;
- }
-
- this.pageRangesAttr = (PageRanges)var1.get(PageRanges.class);
- if (!this.isSupportedValue(this.pageRangesAttr, var1)) {
- this.pageRangesAttr = null;
- } else if ((SunPageSelection)var1.get(SunPageSelection.class) == SunPageSelection.RANGE) {
- int[][] var6 = this.pageRangesAttr.getMembers();
- this.setPageRange(var6[0][0] - 1, var6[0][1] - 1);
- }
-
- Copies var25 = (Copies)var1.get(Copies.class);
- if (!this.isSupportedValue(var25, var1) && (var3 || var25 == null)) {
- this.copiesAttr = this.getCopies();
- } else {
- this.copiesAttr = var25.getValue();
- this.setCopies(this.copiesAttr);
- }
-
- Destination var7 = (Destination)var1.get(Destination.class);
- if (this.isSupportedValue(var7, var1)) {
- try {
- this.destinationAttr = "" + new File(var7.getURI().getSchemeSpecificPart());
- } catch (Exception var23) {
- Destination var9 = (Destination)var2.getDefaultAttributeValue(Destination.class);
- if (var9 != null) {
- this.destinationAttr = "" + new File(var9.getURI().getSchemeSpecificPart());
- }
- }
- }
-
- JobSheets var8 = (JobSheets)var1.get(JobSheets.class);
- if (var8 != null) {
- this.noJobSheet = var8 == JobSheets.NONE;
- }
-
- JobName var26 = (JobName)var1.get(JobName.class);
- if (!this.isSupportedValue(var26, var1) && (var3 || var26 == null)) {
- this.jobNameAttr = this.getJobName();
- } else {
- this.jobNameAttr = var26.getValue();
- this.setJobName(this.jobNameAttr);
- }
-
- RequestingUserName var10 = (RequestingUserName)var1.get(RequestingUserName.class);
- if (!this.isSupportedValue(var10, var1) && (var3 || var10 == null)) {
- try {
- this.userNameAttr = this.getUserName();
- } catch (SecurityException var22) {
- this.userNameAttr = "";
- }
- } else {
- this.userNameAttr = var10.getValue();
- }
-
- Media var11 = (Media)var1.get(Media.class);
- OrientationRequested var12 = (OrientationRequested)var1.get(OrientationRequested.class);
- MediaPrintableArea var13 = (MediaPrintableArea)var1.get(MediaPrintableArea.class);
- if ((var12 != null || var11 != null || var13 != null) && this.getPageable() instanceof OpenBook) {
- Pageable var14 = this.getPageable();
- Printable var15 = var14.getPrintable(0);
- PageFormat var16 = (PageFormat)var14.getPageFormat(0).clone();
- Paper var17 = var16.getPaper();
- if (var13 == null && var11 != null && var2.isAttributeCategorySupported(MediaPrintableArea.class)) {
- Object var18 = var2.getSupportedAttributeValues(MediaPrintableArea.class, (DocFlavor)null, var1);
- if (var18 instanceof MediaPrintableArea[] && ((MediaPrintableArea[])((MediaPrintableArea[])var18)).length > 0) {
- var13 = ((MediaPrintableArea[])((MediaPrintableArea[])var18))[0];
- }
- }
-
- if (this.isSupportedValue(var12, var1) || !var3 && var12 != null) {
- byte var28;
- if (var12.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
- var28 = 2;
- } else if (var12.equals(OrientationRequested.LANDSCAPE)) {
- var28 = 0;
- } else {
- var28 = 1;
- }
-
- var16.setOrientation(var28);
- }
-
- if ((this.isSupportedValue(var11, var1) || !var3 && var11 != null) && var11 instanceof MediaSizeName) {
- MediaSizeName var29 = (MediaSizeName)var11;
- MediaSize var19 = MediaSize.getMediaSizeForName(var29);
- if (var19 != null) {
- float var20 = var19.getX(25400) * 72.0F;
- float var21 = var19.getY(25400) * 72.0F;
- var17.setSize((double)var20, (double)var21);
- if (var13 == null) {
- var17.setImageableArea((double)72.0F, (double)72.0F, (double)var20 - (double)144.0F, (double)var21 - (double)144.0F);
- }
- }
- }
-
- if (this.isSupportedValue(var13, var1) || !var3 && var13 != null) {
- float[] var30 = var13.getPrintableArea(25400);
-
- for(int var31 = 0; var31 < var30.length; ++var31) {
- var30[var31] *= 72.0F;
- }
-
- var17.setImageableArea((double)var30[0], (double)var30[1], (double)var30[2], (double)var30[3]);
- }
-
- var16.setPaper(var17);
- var16 = this.validatePage(var16);
- this.setPrintable(var15, var16);
- } else {
- this.attributes = var1;
- }
-
- }
- }
-
- private void spoolToService(PrintService var1, PrintRequestAttributeSet var2) throws PrinterException {
- if (var1 == null) {
- throw new PrinterException("No print service found.");
- } else {
- DocPrintJob var3 = var1.createPrintJob();
- PageableDoc var4 = new PageableDoc(this.getPageable());
- if (var2 == null) {
- var2 = new HashPrintRequestAttributeSet();
- }
-
- try {
- var3.print(var4, (PrintRequestAttributeSet)var2);
- } catch (PrintException var6) {
- throw new PrinterException(var6.toString());
- }
- }
- }
-
- public void print() throws PrinterException {
- this.print(this.attributes);
- }
-
- protected void debug_println(String var1) {
- if (debugPrint) {
- System.out.println("RasterPrinterJob " + var1 + " " + this);
- }
-
- }
-
- public void print(PrintRequestAttributeSet var1) throws PrinterException {
- PrintService var2 = this.getPrintService();
- this.debug_println("psvc = " + var2);
- if (var2 == null) {
- throw new PrinterException("No print service found.");
- } else {
- PrinterState var3 = (PrinterState)var2.getAttribute(PrinterState.class);
- if (var3 == PrinterState.STOPPED) {
- PrinterStateReasons var4 = (PrinterStateReasons)var2.getAttribute(PrinterStateReasons.class);
- if (var4 != null && var4.containsKey(PrinterStateReason.SHUTDOWN)) {
- throw new PrinterException("PrintService is no longer available.");
- }
- }
-
- if ((PrinterIsAcceptingJobs)var2.getAttribute(PrinterIsAcceptingJobs.class) == PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS) {
- throw new PrinterException("Printer is not accepting job.");
- } else if (var2 instanceof SunPrinterJobService && ((SunPrinterJobService)var2).usesClass(this.getClass())) {
- this.setAttributes(var1);
- if (this.destinationAttr != null) {
- File var29 = new File(this.destinationAttr);
-
- try {
- if (var29.createNewFile()) {
- var29.delete();
- }
- } catch (IOException var26) {
- throw new PrinterException("Cannot write to file:" + this.destinationAttr);
- } catch (SecurityException var27) {
- }
-
- File var5 = var29.getParentFile();
- if (var29.exists() && (!var29.isFile() || !var29.canWrite()) || var5 != null && (!var5.exists() || var5.exists() && !var5.canWrite())) {
- throw new PrinterException("Cannot write to file:" + this.destinationAttr);
- }
- }
-
- this.initPrinter();
- int var30 = this.getCollatedCopies();
- int var31 = this.getNoncollatedCopies();
- this.debug_println("getCollatedCopies() " + var30 + " getNoncollatedCopies() " + var31);
- int var6 = this.mDocument.getNumberOfPages();
- if (var6 != 0) {
- int var7 = this.getFirstPage();
- int var8 = this.getLastPage();
- if (var8 == -1) {
- int var9 = this.mDocument.getNumberOfPages();
- if (var9 != -1) {
- var8 = this.mDocument.getNumberOfPages() - 1;
- }
- }
-
- try {
- synchronized(this) {
- this.performingPrinting = true;
- this.userCancelled = false;
- }
-
- this.startDoc();
- if (this.isCancelled()) {
- this.cancelDoc();
- }
-
- boolean var32 = true;
- if (var1 != null) {
- SunPageSelection var10 = (SunPageSelection)var1.get(SunPageSelection.class);
- if (var10 != null && var10 != SunPageSelection.RANGE) {
- var32 = false;
- }
- }
-
- this.debug_println("after startDoc rangeSelected? " + var32 + " numNonCollatedCopies " + var31);
-
- for(int var33 = 0; var33 < var30; ++var33) {
- int var11 = var7;
-
- for(int var12 = 0; (var11 <= var8 || var8 == -1) && var12 == 0; ++var11) {
- if (this.pageRangesAttr != null && var32) {
- int var13 = this.pageRangesAttr.next(var11);
- if (var13 == -1) {
- break;
- }
-
- if (var13 != var11 + 1) {
- continue;
- }
- }
-
- for(int var34 = 0; var34 < var31 && var12 == 0; ++var34) {
- if (this.isCancelled()) {
- this.cancelDoc();
- }
-
- this.debug_println("printPage " + var11);
- var12 = this.printPage(this.mDocument, var11);
- }
- }
- }
-
- if (this.isCancelled()) {
- this.cancelDoc();
- }
- } finally {
- synchronized(this) {
- if (this.performingPrinting) {
- this.endDoc();
- }
-
- this.performingPrinting = false;
- this.notify();
- }
- }
-
- }
- } else {
- this.spoolToService(var2, var1);
- }
- }
- }
-
- protected void validatePaper(Paper var1, Paper var2) {
- if (var1 != null && var2 != null) {
- double var3 = var1.getWidth();
- double var5 = var1.getHeight();
- double var7 = var1.getImageableX();
- double var9 = var1.getImageableY();
- double var11 = var1.getImageableWidth();
- double var13 = var1.getImageableHeight();
- Paper var15 = new Paper();
- var3 = var3 > (double)0.0F ? var3 : var15.getWidth();
- var5 = var5 > (double)0.0F ? var5 : var15.getHeight();
- var7 = var7 > (double)0.0F ? var7 : var15.getImageableX();
- var9 = var9 > (double)0.0F ? var9 : var15.getImageableY();
- var11 = var11 > (double)0.0F ? var11 : var15.getImageableWidth();
- var13 = var13 > (double)0.0F ? var13 : var15.getImageableHeight();
- if (var11 > var3) {
- var11 = var3;
- }
-
- if (var13 > var5) {
- var13 = var5;
- }
-
- if (var7 + var11 > var3) {
- var7 = var3 - var11;
- }
-
- if (var9 + var13 > var5) {
- var9 = var5 - var13;
- }
-
- var2.setSize(var3, var5);
- var2.setImageableArea(var7, var9, var11, var13);
- }
- }
-
- public PageFormat defaultPage(PageFormat var1) {
- PageFormat var2 = (PageFormat)var1.clone();
- var2.setOrientation(1);
- Paper var3 = new Paper();
- double var4 = (double)72.0F;
- Object var10 = null;
- PrintService var11 = this.getPrintService();
- if (var11 != null) {
- Media var17 = (Media)var11.getDefaultAttributeValue(Media.class);
- MediaSize var12;
- if (var17 instanceof MediaSizeName && (var12 = MediaSize.getMediaSizeForName((MediaSizeName)var17)) != null) {
- double var15 = (double)var12.getX(25400) * var4;
- double var16 = (double)var12.getY(25400) * var4;
- var3.setSize(var15, var16);
- var3.setImageableArea(var4, var4, var15 - (double)2.0F * var4, var16 - (double)2.0F * var4);
- var2.setPaper(var3);
- return var2;
- }
- }
-
- String var18 = Locale.getDefault().getCountry();
- if (!Locale.getDefault().equals(Locale.ENGLISH) && var18 != null && !var18.equals(Locale.US.getCountry()) && !var18.equals(Locale.CANADA.getCountry())) {
- double var13 = 25.4;
- double var6 = Math.rint((double)210.0F * var4 / var13);
- double var8 = Math.rint((double)297.0F * var4 / var13);
- var3.setSize(var6, var8);
- var3.setImageableArea(var4, var4, var6 - (double)2.0F * var4, var8 - (double)2.0F * var4);
- }
-
- var2.setPaper(var3);
- return var2;
- }
-
- public PageFormat validatePage(PageFormat var1) {
- PageFormat var2 = (PageFormat)var1.clone();
- Paper var3 = new Paper();
- this.validatePaper(var2.getPaper(), var3);
- var2.setPaper(var3);
- return var2;
- }
-
- public void setCopies(int var1) {
- this.mNumCopies = var1;
- }
-
- public int getCopies() {
- return this.mNumCopies;
- }
-
- protected int getCopiesInt() {
- return this.copiesAttr > 0 ? this.copiesAttr : this.getCopies();
- }
-
- public String getUserName() {
- return System.getProperty("user.name");
- }
-
- protected String getUserNameInt() {
- if (this.userNameAttr != null) {
- return this.userNameAttr;
- } else {
- try {
- return this.getUserName();
- } catch (SecurityException var2) {
- return "";
- }
- }
- }
-
- public void setJobName(String var1) {
- if (var1 != null) {
- this.mDocName = var1;
- } else {
- throw new NullPointerException();
- }
- }
-
- public String getJobName() {
- return this.mDocName;
- }
-
- protected String getJobNameInt() {
- return this.jobNameAttr != null ? this.jobNameAttr : this.getJobName();
- }
-
- protected void setPageRange(int var1, int var2) {
- if (var1 >= 0 && var2 >= 0) {
- this.mFirstPage = var1;
- this.mLastPage = var2;
- if (this.mLastPage < this.mFirstPage) {
- this.mLastPage = this.mFirstPage;
- }
- } else {
- this.mFirstPage = -1;
- this.mLastPage = -1;
- }
-
- }
-
- protected int getFirstPage() {
- return this.mFirstPage == -1 ? 0 : this.mFirstPage;
- }
-
- protected int getLastPage() {
- return this.mLastPage;
- }
-
- protected void setCollated(boolean var1) {
- this.mCollate = var1;
- this.collateAttReq = true;
- }
-
- protected boolean isCollated() {
- return this.mCollate;
- }
-
- protected abstract void startDoc() throws PrinterException;
-
- protected abstract void endDoc() throws PrinterException;
-
- protected abstract void abortDoc();
-
- private void cancelDoc() throws PrinterAbortException {
- this.abortDoc();
- synchronized(this) {
- this.userCancelled = false;
- this.performingPrinting = false;
- this.notify();
- }
-
- throw new PrinterAbortException();
- }
-
- protected int getCollatedCopies() {
- return this.isCollated() ? this.getCopiesInt() : 1;
- }
-
- protected int getNoncollatedCopies() {
- return this.isCollated() ? 1 : this.getCopiesInt();
- }
-
- synchronized void setGraphicsConfigInfo(AffineTransform var1, double var2, double var4) {
- Point2D.Double var6 = new Point2D.Double(var2, var4);
- var1.transform(var6, var6);
- if (this.pgConfig == null || this.defaultDeviceTransform == null || !var1.equals(this.defaultDeviceTransform) || this.deviceWidth != (int)var6.getX() || this.deviceHeight != (int)var6.getY()) {
- this.deviceWidth = (int)var6.getX();
- this.deviceHeight = (int)var6.getY();
- this.defaultDeviceTransform = var1;
- this.pgConfig = null;
- }
-
- }
-
- synchronized PrinterGraphicsConfig getPrinterGraphicsConfig() {
- if (this.pgConfig != null) {
- return this.pgConfig;
- } else {
- String var1 = "Printer Device";
- PrintService var2 = this.getPrintService();
- if (var2 != null) {
- var1 = var2.toString();
- }
-
- this.pgConfig = new PrinterGraphicsConfig(var1, this.defaultDeviceTransform, this.deviceWidth, this.deviceHeight);
- return this.pgConfig;
- }
- }
-
- protected int printPage(Pageable var1, int var2) throws PrinterException {
- PageFormat var3;
- PageFormat var4;
- Printable var5;
- try {
- var4 = var1.getPageFormat(var2);
- var3 = (PageFormat)var4.clone();
- var5 = var1.getPrintable(var2);
- } catch (Exception var40) {
- throw new PrinterException("No page or printable exists.");
- }
-
- Paper var6 = var3.getPaper();
- if (var3.getOrientation() != 1 && this.landscapeRotates270) {
- double var7 = var6.getImageableX();
- double var9 = var6.getImageableY();
- double var11 = var6.getImageableWidth();
- double var13 = var6.getImageableHeight();
- var6.setImageableArea(var6.getWidth() - var7 - var11, var6.getHeight() - var9 - var13, var11, var13);
- var3.setPaper(var6);
- if (var3.getOrientation() == 0) {
- var3.setOrientation(2);
- } else {
- var3.setOrientation(0);
- }
- }
-
- double var41 = this.getXRes() / (double)72.0F;
- double var42 = this.getYRes() / (double)72.0F;
- Rectangle2D.Double var43 = new Rectangle2D.Double(var6.getImageableX() * var41, var6.getImageableY() * var42, var6.getImageableWidth() * var41, var6.getImageableHeight() * var42);
- AffineTransform var12 = new AffineTransform();
- AffineTransform var44 = new AffineTransform();
- var44.scale(var41, var42);
- int var14 = (int)((Rectangle2D)var43).getWidth();
- if (var14 % 4 != 0) {
- var14 += 4 - var14 % 4;
- }
-
- if (var14 <= 0) {
- throw new PrinterException("Paper's imageable width is too small.");
- } else {
- int var15 = (int)((Rectangle2D)var43).getHeight();
- if (var15 <= 0) {
- throw new PrinterException("Paper's imageable height is too small.");
- } else {
- int var16 = 4194304 / var14 / 3;
- int var17 = (int)Math.rint(var6.getImageableX() * var41);
- int var18 = (int)Math.rint(var6.getImageableY() * var42);
- AffineTransform var19 = new AffineTransform();
- var19.translate((double)(-var17), (double)var18);
- var19.translate((double)0.0F, (double)var16);
- var19.scale((double)1.0F, (double)-1.0F);
- BufferedImage var20 = new BufferedImage(1, 1, 5);
- PeekGraphics var21 = this.createPeekGraphics(var20.createGraphics(), this);
- Rectangle2D.Double var22 = new Rectangle2D.Double(var3.getImageableX(), var3.getImageableY(), var3.getImageableWidth(), var3.getImageableHeight());
- var21.transform(var44);
- var21.translate(-this.getPhysicalPrintableX(var6) / var41, -this.getPhysicalPrintableY(var6) / var42);
- var21.transform(new AffineTransform(var3.getMatrix()));
- this.initPrinterGraphics(var21, var22);
- AffineTransform var23 = var21.getTransform();
- this.setGraphicsConfigInfo(var44, var6.getWidth(), var6.getHeight());
- int var24 = var5.print(var21, var4, var2);
- this.debug_println("pageResult " + var24);
- if (var24 == 0) {
- this.debug_println("startPage " + var2);
- this.startPage(var3, var5, var2);
- Graphics2D var25 = this.createPathGraphics(var21, this, var5, var3, var2);
- if (var25 != null) {
- var25.transform(var44);
- var25.translate(-this.getPhysicalPrintableX(var6) / var41, -this.getPhysicalPrintableY(var6) / var42);
- var25.transform(new AffineTransform(var3.getMatrix()));
- this.initPrinterGraphics(var25, var22);
- this.redrawList.clear();
- AffineTransform var45 = var25.getTransform();
- var5.print(var25, var4, var2);
-
- for(int var46 = 0; var46 < this.redrawList.size(); ++var46) {
- GraphicsState var47 = (GraphicsState)this.redrawList.get(var46);
- var25.setTransform(var45);
- ((PathGraphics)var25).redrawRegion(var47.region, var47.sx, var47.sy, var47.theClip, var47.theTransform);
- }
- } else {
- BufferedImage var26 = this.cachedBand;
- if (this.cachedBand == null || var14 != this.cachedBandWidth || var16 != this.cachedBandHeight) {
- var26 = new BufferedImage(var14, var16, 5);
- this.cachedBand = var26;
- this.cachedBandWidth = var14;
- this.cachedBandHeight = var16;
- }
-
- Graphics2D var27 = var26.createGraphics();
- Rectangle2D.Double var28 = new Rectangle2D.Double((double)0.0F, (double)0.0F, (double)var14, (double)var16);
- this.initPrinterGraphics(var27, var28);
- ProxyGraphics2D var29 = new ProxyGraphics2D(var27, this);
- Graphics2D var30 = var26.createGraphics();
- var30.setColor(Color.white);
- ByteInterleavedRaster var31 = (ByteInterleavedRaster)var26.getRaster();
- byte[] var32 = var31.getDataStorage();
- int var10000 = var18 + var15;
- int var34 = (int)this.getPhysicalPrintableX(var6);
- int var35 = (int)this.getPhysicalPrintableY(var6);
-
- for(int var36 = 0; var36 <= var15; var36 += var16) {
- var30.fillRect(0, 0, var14, var16);
- var27.setTransform(var12);
- var27.transform(var19);
- var19.translate((double)0.0F, (double)(-var16));
- var27.transform(var44);
- var27.transform(new AffineTransform(var3.getMatrix()));
- Rectangle var37 = var27.getClipBounds();
- var37 = var23.createTransformedShape(var37).getBounds();
- if (var37 == null || var21.hitsDrawingArea(var37) && var14 > 0 && var16 > 0) {
- int var38 = var17 - var34;
- if (var38 < 0) {
- var27.translate((double)var38 / var41, (double)0.0F);
- var38 = 0;
- }
-
- int var39 = var18 + var36 - var35;
- if (var39 < 0) {
- var27.translate((double)0.0F, (double)var39 / var42);
- var39 = 0;
- }
-
- var29.setDelegate((Graphics2D)var27.create());
- var5.print(var29, var4, var2);
- var29.dispose();
- this.printBand(var32, var38, var39, var14, var16);
- }
- }
-
- var30.dispose();
- var27.dispose();
- }
-
- this.debug_println("calling endPage " + var2);
- this.endPage(var3, var5, var2);
- }
-
- return var24;
- }
- }
- }
-
- public void cancel() {
- synchronized(this) {
- if (this.performingPrinting) {
- this.userCancelled = true;
- }
-
- this.notify();
- }
- }
-
- public boolean isCancelled() {
- boolean var1 = false;
- synchronized(this) {
- var1 = this.performingPrinting && this.userCancelled;
- this.notify();
- return var1;
- }
- }
-
- protected Pageable getPageable() {
- return this.mDocument;
- }
-
- protected Graphics2D createPathGraphics(PeekGraphics var1, PrinterJob var2, Printable var3, PageFormat var4, int var5) {
- return null;
- }
-
- protected PeekGraphics createPeekGraphics(Graphics2D var1, PrinterJob var2) {
- return new PeekGraphics(var1, var2);
- }
-
- void initPrinterGraphics(Graphics2D var1, Rectangle2D var2) {
- var1.setClip(var2);
- var1.setPaint(Color.black);
- }
-
- public boolean checkAllowedToPrintToFile() {
- try {
- this.throwPrintToFile();
- return true;
- } catch (SecurityException var2) {
- return false;
- }
- }
-
- private void throwPrintToFile() {
- SecurityManager var1 = System.getSecurityManager();
- if (var1 != null) {
- if (this.printToFilePermission == null) {
- this.printToFilePermission = new FilePermission("<<ALL FILES>>", "read,write");
- }
-
- var1.checkPermission(this.printToFilePermission);
- }
-
- }
-
- protected String removeControlChars(String var1) {
- char[] var2 = var1.toCharArray();
- int var3 = var2.length;
- char[] var4 = new char[var3];
- int var5 = 0;
-
- for(int var6 = 0; var6 < var3; ++var6) {
- char var7 = var2[var6];
- if (var7 > '\r' || var7 < '\t' || var7 == 11 || var7 == '\f') {
- var4[var5++] = var7;
- }
- }
-
- if (var5 == var3) {
- return var1;
- } else {
- return new String(var4, 0, var5);
- }
- }
-
- static {
- String var0 = (String)AccessController.doPrivileged(new GetPropertyAction("sun.java2d.print.pipeline"));
- if (var0 != null) {
- if (var0.equalsIgnoreCase("pdl")) {
- forcePDL = true;
- } else if (var0.equalsIgnoreCase("raster")) {
- forceRaster = true;
- }
- }
-
- String var1 = (String)AccessController.doPrivileged(new GetPropertyAction("sun.java2d.print.shapetext"));
- if (var1 != null) {
- shapeTextProp = true;
- }
-
- debugPrint = false;
- }
- }
-